package dicky.fortunetelling.logic;

import java.util.HashMap;
import java.util.List;


import dicky.fortunetelling.R;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;

public class CommonUtil {
	private static String tag=CommonUtil.class.getSimpleName();
	public static int GetFiveColor(String five){
		int c=R.color.black;
		
		if (five.indexOf("金")>=0){
			c=R.color.gold;
		}
		if (five.indexOf("木")>=0){
			c=R.color.green;
		}
		if (five.indexOf("水")>=0){
			c=R.color.blue;
		}
		if (five.indexOf("火")>=0){
			c=R.color.red;
		}
		if (five.indexOf("土")>=0){
			c=R.color.orange;
		}
		if (five.length()==3){
			c=R.color.black;
		}
		return c;
	}
	
	public static void GetGoodNumber(Context ctx){
		String msg="";
		try {
			List list=DataArray.GoodNumberList();
			HashMap map=null;
			for(int i=0;i<list.size();i++){
				map=(HashMap)list.get(i);
				msg+="".equals(msg)?"":"\n\n";
				msg+="理数：";
				msg+=map.get("num");
				msg+="\n吉凶：";
				msg+="\n\t"+map.get("text1");
				msg+="\n\t"+map.get("text2");
			}
			
			AlertDialog.Builder dialog = new AlertDialog.Builder(ctx);
			
			dialog.setMessage(msg);
			dialog.setTitle("吉数列表");
			dialog.setCancelable(true);
			dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			dialog.create().show();
			/*
			List list=DataArray.GoodNumberList();
			GoodNumberDlg dlg = new GoodNumberDlg(activity, list);
			dlg.show();
			
			List list=DataArray.GoodNumberList();
			goodNumberAdapter = GoodNumberAdapter.GoodNumberAdapter(activity, R.layout.goodnumberlist,list);
            Builder dialog=new AlertDialog.Builder(activity);
            dialog.setTitle("吉数列表");
            dialog.setAdapter(goodNumberAdapter, null);
            //不要忘记下面这句
            dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }  
            });
            dialog.show();
            */
		} catch (Exception e) {
			Log.d(tag, e+"");
		}
	}
}
